home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tjoop11.zip / QUEUEOBJ.PAS < prev    next >
Pascal/Delphi Source File  |  1991-05-17  |  5KB  |  200 lines

  1. UNIT QueueOBJ ;
  2.  
  3.  
  4.  
  5.  
  6. {**********************************************************************
  7.  *                                                                    *
  8.  *  PROGRAM :  QueueOBJ                PC FILE NAME :  QueueOBJ.PAS   *
  9.  *  ----------------------------------------------------------------  *
  10.  *  LIBRARY MODULES USED :  DOS CRT                                   *
  11.  *  BaseType :  TP6.0 TPU SOURCE: BASETYPE.PAS  BINARY:  BASETPYE.TPU *
  12.  *  ----------------------------------------------------------------  *
  13.  *  PURPOSE :  The purpose of this UNIT is to provide a Queue object  *
  14.  *             that uses a common base and base element object.       *
  15.  *  ----------------------------------------------------------------  *
  16.  *  AUTHOR   :  Thomas E. Jenkins, Jr.                                *
  17.  *              PROGRAMMER, UNIVERSITY OF SOUTH CAROLINA, USA         *
  18.  *  BITNET   :  C0361@UNIVSCVM.BITNET                                 *
  19.  *  INTERNET :  C0361@univscvm.csd.scarolina.EDU                      *
  20.  *              tomj@csdserver3.csd.scarolina.EDU                     *
  21.  *  ----------------------------------------------------------------  *
  22.  *  DISCAIMER :  This program has been tested to the best of my       *
  23.  *               abilities.  The author claims no responsibility      *
  24.  *               for the performance or side effects this program     *
  25.  *               may yield.                                           *
  26.  *  ----------------------------------------------------------------  *
  27.  *  DISTIBUTION :  This program is given freely to the PD realms.     *
  28.  *                 It may freely be copied and distributed.  Any      *
  29.  *                 one wishing to use some or whole parts of this     *
  30.  *                 program for commercial use please contact the      *
  31.  *                 author first.                                      *
  32.  *                                                                    *
  33.  **********************************************************************}
  34.  
  35.  
  36.  
  37.  
  38.                                   INTERFACE
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.              {
  46.  
  47.  
  48.                  Here is a basic view of the Queue object tree:
  49.  
  50.                  TObject                    [ to allow use with streams   ]
  51.                     |
  52.                     |
  53.                     \___ TBaseOBJ           [ basic functions of Queue &  ]
  54.                              |              [ elements                    ]
  55.                              |
  56.                              \___ TElementOBJ    [ basic functionality of ]
  57.                              /         |         [ any element            ]
  58.                              |         |
  59.                              |         \___ TStrOBJ [ string specific     ]
  60.                              |         /            [ functions & storage ]
  61.                              |         |
  62.                              |         |
  63.                              |         \___ TIntOBJ [ integer specific    ]
  64.                              |         /            [ functions & storage ]
  65.                              |         |
  66.                              |         |
  67.                              |         \___ TRealOBJ [ real specific      ]
  68.                              |                       [ functions & storage]
  69.                              |
  70.                              \___ TQueueOBJ      [ Queue specific         ]
  71.                                                  [ functions & storage    ]
  72.  
  73.              }
  74.  
  75.  
  76. USES
  77.        BaseTypes ;
  78.  
  79.  
  80.  
  81. TYPE
  82.  
  83.        PQueueOBJ                       = ^TQueueOBJ ;
  84.        TQueueOBJ                       = OBJECT ( TBaseOBJ )
  85.  
  86.          head                          : PElementOBJ ;
  87.          tail                          : PElementOBJ ;
  88.  
  89.          CONSTRUCTOR Init ;
  90.  
  91.          PROCEDURE   Add (     item    : PElementOBJ ) ;
  92.            VIRTUAL ;
  93.  
  94.          FUNCTION    Get               : PElementOBJ ;
  95.            VIRTUAL ;
  96.  
  97.          FUNCTION    Empty             : BOOLEAN ;
  98.            VIRTUAL ;
  99.  
  100.          DESTRUCTOR  Done ;
  101.            VIRTUAL ;
  102.  
  103.          END ;  {  TQueueOBJ  }
  104.  
  105.  
  106.  
  107.  
  108.                                 IMPLEMENTATION
  109.  
  110.  
  111.  
  112.  
  113.  CONSTRUCTOR TQueueOBJ.Init ;
  114.  
  115.    BEGIN  {  TQueueOBJ.Init  }
  116.  
  117.      head := NIL ;
  118.      tail := NIL ;
  119.  
  120.      END ;  {  TQueueOBJ.Init  }
  121.  
  122.  
  123.  
  124.  
  125.  PROCEDURE   TQueueOBJ.Add (     item  : PElementOBJ ) ;
  126.  
  127.   BEGIN  {  TQueueOBJ.Add  }
  128.  
  129.     IF ( head = NIL )
  130.      THEN
  131.       BEGIN
  132.  
  133.         head := item ;
  134.         tail := item ;
  135.  
  136.         Exit ;
  137.  
  138.         END ;  {  THEN  }
  139.  
  140.     tail^.last := item ;
  141.  
  142.     tail := item ;
  143.  
  144.     END ;  {  TQueueOBJ.Add  }
  145.  
  146.  
  147.  
  148.  
  149.  FUNCTION    TQueueOBJ.Get                       : PElementOBJ ;
  150.  
  151.   BEGIN  {  TQueueOBJ.Get  }
  152.  
  153.     Get := head ;
  154.  
  155.     IF ( Empty )
  156.      THEN
  157.         Exit ;
  158.  
  159.     head := head^.last ;
  160.  
  161.     IF ( head = NIL )
  162.      THEN
  163.         tail := head ;
  164.  
  165.     END ;  {  TQueueOBJ.Get  }
  166.  
  167.  
  168.  
  169.  
  170.  FUNCTION    TQueueOBJ.Empty                     : BOOLEAN ;
  171.  
  172.   BEGIN  {  TQueueOBJ.Empty  }
  173.  
  174.     Empty := ( head = NIL ) ;
  175.  
  176.     END ;  {  TQueueOBJ.Empty  }
  177.  
  178.  
  179.  
  180.  
  181.  DESTRUCTOR  TQueueOBJ.Done ;
  182.  
  183.    BEGIN  {  TQueueOBJ.Done  }
  184.  
  185.      WHILE ( head <> NIL )
  186.       DO
  187.        BEGIN
  188.  
  189.          Dispose ( Get , Done ) ;
  190.  
  191.          END ;  {  WHILE  }
  192.  
  193.      tail := head ;
  194.  
  195.      END ;  {  TQueueOBJ.Done  }
  196.  
  197.  
  198.  
  199.  
  200. END .